﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QLNS.Models
{
    public class CapNgoaiNguModels
    {
        public static CapNgoaiNgu GetChiTietDSCapNgoaiNgu(int id)
        {
            //khoi tao db
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            var query = (from s in context.DSCapNgoaiNgu
                         where s.ID == id
                         select s).FirstOrDefault();
            return query;

        }

        //danh sach dantoc
        public static List<CapNgoaiNgu> GetDSCapNgoaiNgu()
        {
            //khoi tao db
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            var query = from dt in context.DSCapNgoaiNgu
                        select dt;
            return query.ToList<CapNgoaiNgu>();
        }
        //them vao bang dan toc
        public static void Add(CapNgoaiNgu th)
        {
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            context.DSCapNgoaiNgu.AddObject(th);
            context.SaveChanges();
        }
        //Xoa Dan Toc
        public static void Delete(int id)
        {
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            var query = (from h in context.DSCapNgoaiNgu
                         where h.ID == id
                         select h).FirstOrDefault();

            context.DSCapNgoaiNgu.DeleteObject(query);
            context.SaveChanges();

        }

        //sua dan toc
        public static void Edit(CapNgoaiNgu id)
        {
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            var query = from h in context.DSCapNgoaiNgu
                        where h.ID == id.ID
                        select h;
            CapNgoaiNgu kq = query.First<CapNgoaiNgu>();
            kq = id;
            context.DSCapNgoaiNgu.ApplyCurrentValues(kq);
            context.SaveChanges();

        }
    }
}